#include <memory>
#include <iostream>

using std::cout;
using std::endl;
using std::shared_ptr;

class Child;//类的前向声明

class Parent
{
public:
    Parent()
    {   cout << "Parent()" << endl; }

    ~Parent()
    {   cout << "~Parent()" << endl;    }

    shared_ptr<Child> _spChild;
};

class Child
{
public:
    Child()
    {   cout << "Child()" << endl; }

    ~Child()
    {   cout << "~Child()" << endl;    }

    shared_ptr<Parent> _spParent;
};

int main()
{
    shared_ptr<Parent> spParent(new Parent);
    shared_ptr<Child> spChild(new Child);
    cout << "spParent 's use_count:" << spParent.use_count() << endl;
    cout << "spChild's use_count:" << spChild.use_count() << endl;
    cout << endl;

    spParent->_spChild = spChild;
    spChild->_spParent = spParent;
    cout << "spParent 's use_count:" << spParent.use_count() << endl;
    cout << "spChild's use_count:" << spChild.use_count() << endl;

    return 0;
}

